package com.josework.springhelloworld.entity.Cup;

import org.springframework.util.CollectionUtils;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.function.Supplier;
import java.util.stream.Collectors;
import java.util.stream.Stream;

public class CupDto {

    private String name;

    public CupDto(String name){
        this.name = name;
    }

    public static List<CupDto> getCupDtoList(List<Cup> cupList){
        List<CupDto> res = Collections.emptyList();
        if (!CollectionUtils.isEmpty(cupList)){
            res = cupList.stream().map(
                    e -> {
                        return new CupDto(e.getName());
                    }
            ).collect(Collectors.toList());
        }
        return res;
    }

    public static void main(String[] args) {
        Cup cup1 = new Cup("cup1",1000,50);
        Cup cup2 = new Cup("cup2",500,30);
        List<Cup> cupList = new ArrayList<>();
        cupList.add(cup1);
        cupList.add(cup2);
        List<CupDto> cupDtoList = getCupDtoList(cupList);

        List<Integer> integers = Stream.of(1.0, 2.0, 3.5)
                .map(Double::intValue)
                .collect(Collectors.toList());
//        Stream.of("d2","a2","b1","b3","c")
//                .filter(s -> {
//                    System.out.println("filter:" + s);
//                    return true;
//                })
//                .forEach(s -> System.out.println("forEach:" + s));
        Supplier<Stream<String>> stream = () -> Stream.of("d2", "a2", "b1", "b3", "c")
                .filter(s -> {
                    System.out.println("filter:" + s);
                    return s.startsWith("a") || s.startsWith("b");
                })
                .sorted((s1, s2) -> {
                    System.out.printf("sort: %s; %s\n", s1, s2);
                    return s1.compareTo(s2);
                })
                .map(s -> {
                    System.out.println("map:" + s);
                    return s.toUpperCase();
                });

        boolean b = stream.get().anyMatch(s -> true);
        boolean b1 = stream.get().noneMatch(s -> true);



    }
}
